<template>
	<view>
		<view class="main">
			<view class="shuru" v-if="redPayStatus==0||redPayStatus==1">
				<text class="shuru_tit t1">红包利率设置开关</text>
				<switch class="shuru_text t1" :checked="checks" @change="checki"></switch>
			</view>
			<view class="shuru" v-if="wechatPayStatus==0||wechatPayStatus==1">
				<text class="shuru_tit t1">微信支付开关</text>
				<switch class="shuru_text t1" :checked="checks1" @change="checki1"></switch>
			</view>
			<view class="shuru" v-if="aliPayStatus==0||aliPayStatus==1">
				<text class="shuru_tit t1">支付宝支付开关</text>
				<switch class="shuru_text t1" :checked="checks2" @change="checki2"></switch>
			</view>
			<view class="shuru t1" v-if="redPayStatus!=0&&redPayStatus!=1" style="padding: 4vw;">
				您还没有审核通过微信或支付宝支付，请先去查看申请进度。</view>
		</view>
		<view class="tuic t2" @click="shezhi()" v-if="redPayStatus==0||redPayStatus==1">确定</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				lilv: '',
				tian: '',
				checks: false,
				checks1: false,
				checks2: false,
				mainid: '',
				aliPayStatus: '',
				redPayStatus: '',
				wechatPayStatus: '',
			}
		},
		onLoad() {
			var _this = this;
			uni.getStorage({
				key: 'user',
				success: function(res) {
					_this.mainid = res.data.id;
					_this.kaiguan();
				}
			});
		},
		methods: {
			checki(e) {
				console.log(e);
				this.checks = e.detail.value;
				if (e.detail.value == false) {
					this.redPayStatus = 0
				} else {

					this.redPayStatus = 1
				}
			},
			checki1(e) {
				console.log(e);
				this.checks1 = e.detail.value;
				if (e.detail.value == false) {
					this.wechatPayStatus = 0
				} else {

					this.wechatPayStatus = 1
				}
			},
			checki2(e) {
				console.log(e);
				this.checks2 = e.detail.value;
				if (e.detail.value == false) {
					this.aliPayStatus = 0
				} else {

					this.aliPayStatus = 1
				}
				// console.log(this.aliPayStatus);
			},
			tishis(e) {
				this.tishi = true;
				// console.log(e);
				this.delid = e;

			},
			clos() {
				this.tishi = false;

			},
			kaiguan() {
				var _this = this;
				uni.request({
					header: {
						'Content-Type': 'application/x-www-form-urlencoded', //自定义请求头信息
					},
					url: getApp().globalData.url + 'mch/getSwitch/' + _this.mainid, //仅为示例，并非真实接口地址。
					method: 'POST',
					data: {
						"id": _this.mainid,
					},
					success: (res) => {
						uni.hideLoading(); //关闭加载动画
						console.log(res);
						if (res.data.status == '200') {
							if(res.data.data.aliPayStatus==1){
								_this.checks2=true;
							}else{
								_this.checks2=false;
							}
							if(res.data.data.redPayStatus==1){
								_this.checks=true;
							}else{
								_this.checks=false;
							}
							if(res.data.data.wechatPayStatus==1){
								_this.checks1=true;
							}else{
								_this.checks1=false;
							}
							_this.aliPayStatus = res.data.data.aliPayStatus;
							_this.redPayStatus = res.data.data.redPayStatus;
							_this.wechatPayStatus = res.data.data.wechatPayStatus;
						} else {
							uni.showToast({
								title: res.data.msg,
								icon: 'none',
								duration: 2000
							});
						}
					},
					fail: (error) => {
						// this.checks = true
						console.log(error)
					}
				});
			},
			shezhi() {
				var _this = this;
				uni.request({
					header: {
						'Content-Type': 'application/json', //自定义请求头信息
					},
					url: getApp().globalData.url + 'mch/switch', //仅为示例，并非真实接口地址。
					method: 'POST',
					data: {
						aliPayStatus: _this.aliPayStatus, //	阿里支付状态		false							integer
						id: _this.mainid, //	商户ID		false							string
						redPayStatus: _this.redPayStatus, //	红包营销开关		false							integer
						wechatPayStatus: _this.wechatPayStatus, //	微信支付状态		false							integer
					},
					success: (res) => {
						uni.hideLoading(); //关闭加载动画
						console.log(res);
						if (res.data.status == '200') {
							uni.showToast({
								title: '红包设置成功',
								icon: 'none',
								duration: 2000
							});
							setTimeout(function() {

								uni.navigateBack({
									delta: 1
								})
							}, 2000)
						} else {
							uni.showToast({
								title: res.data.msg,
								icon: 'none',
								duration: 2000
							});
						}
					},
					fail: (error) => {
						// this.checks = true
						console.log(error)
					}
				});
			},
		}
	}
</script>

<style>
	.baodan_xuzhi_main {
		width: 100%;
		height: 100vh;
		display: block;
		float: left;
		background: url(../../static/img/bg.png) repeat;
		position: fixed;
		top: 0;
		left: 0;
	}

	.baodan_xuzhi_tit {
		width: 100%;
		height: 8vw;
		line-height: 8vw;
		display: block;
		float: left;
		text-align: center;
	}

	.baodan_xuzhi_info {
		width: 100%;
		height: auto;
		display: block;
		float: left;
		line-height: 7vw;
		margin-top: 2vw;
	}

	.baodan_clo {
		width: 6vw;
		height: 6vw;
		display: block;
		float: left;
		position: absolute;
		top: 2vw;
		right: 2vw;
		border-radius: 50%;
		border: 1px solid #000;
		padding: 1vw;
	}

	.baodan_clo image {
		width: 3.7vw;
		height: 3.7vw;
		display: block;
		float: left;
	}

	.kaitong {
		width: 80%;
		height: 12vw;
		display: block;
		float: left;
		background: url(../../static/img/but1.png) no-repeat top center;
		background-size: 100%;
		margin: 2vw 10%;
		text-align: center;
		line-height: 12vw;
	}

	.center_top {
		width: 100%;
		height: auto;
		display: block;
		float: left;
	}

	.baodan_list {
		width: 90%;
		height: auto;
		display: block;
		float: left;
		margin: 2vw 5%;
		background: #fff;
		border-radius: 2vw;
		padding: 4vw;
		box-shadow: 0px 0px 1vw #ccc;
		margin-top: 4vw;
	}

	.baodan_list_tit {
		width: 75%;
		height: auto;
		display: block;
		float: left;
	}

	.baodan_but {
		width: 20%;
		height: 6vw;
		display: block;
		float: right;
		border-radius: 2vw;
		background: url(../../static/img/but.png) no-repeat top center;
		background-size: 100%;
		line-height: 6vw;
		text-align: center;
		margin-top: 3vw;
	}

	.baodan_xuzhi {
		width: 80%;
		height: auto;
		display: block;
		float: left;
		background: #fff;
		box-shadow: 0px 0px 2vw #999;
		padding: 4vw;
		position: fixed;
		top: 40vw;
		left: 10%;
		border-radius: 2vw;
	}

	.baodan_xuzhi_tit {
		width: 100%;
		height: 8vw;
		line-height: 8vw;
		display: block;
		float: left;
		text-align: center;
	}

	.baodan_into {
		position: relative;
		width: 100%;
		height: auto;
		display: block;
		float: left;
		line-height: 7vw;
		margin-top: 2vw;
		overflow: hidden;
	}

	.baodan_into::after {
		width: 7vw;
		height: 7vw;
		content: "…";
		position: absolute;
		top: 0;
		right: 0;
		background: #fff;
		padding-left: 2vw;
		display: block;
		float: right;
	}

	.shuru {
		width: 100%;
		height: auto;
		display: block;
		float: left;
		border-radius: 1vw;
		overflow: hidden;
		padding: 2vw 4vw;
		background: #fff;
		margin-top: 3vw;
		box-shadow: 0px 0px 5px #eee;
	}

	.shuru_tit {
		width: 30%;
		height: 10vw;
		line-height: 10vw;
		display: block;
		float: left;
	}

	.shuru_text {
		width: 60%;
		height: 10vw;
		line-height: 10vw;
		display: block;
		float: right;
		text-align: right;
	}
</style>
